package com.websuites.dao;

import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.JdbcTemplate;

@SuppressWarnings("unchecked")
public class JdbcTemplateDao
{
	private Map jdbcTemplates; 

	private String defaultDataSource = "defaultDataSource";
	
	public String getDefaultDataSource() {
		return defaultDataSource;
	}

	public void setDefaultDataSource(String defaultDataSource) {
		this.defaultDataSource = defaultDataSource;
	}

	public void setJdbcTemplates(Map jdbcTemplates) 
	{
		this.jdbcTemplates = jdbcTemplates;
	}

	public JdbcTemplate getJdbcTemplate() 
	{
		return (JdbcTemplate)jdbcTemplates.get(this.defaultDataSource);
	}

	public JdbcTemplate getJdbcTemplate(String sDataSource) 
	{
		return (JdbcTemplate)jdbcTemplates.get(sDataSource);
	}
	
	public int queryJdbcTemplateInt(String sSql)
	{
		return this.getJdbcTemplate().queryForInt(sSql);
	}

	public int queryJdbcTemplateInt(String sDataSource, String sSql)
	{
		return this.getJdbcTemplate(sDataSource).queryForInt(sSql);
	}
	
	public int queryJdbcTemplateInt(String sSql, Object[] args)
	{
		return this.getJdbcTemplate().queryForInt(sSql, args);
	}

	public int queryJdbcTemplateInt(String sDataSource, String sSql, Object[] args)
	{
		return this.getJdbcTemplate(sDataSource).queryForInt(sSql, args);
	}

	public Object queryJdbcTemplateObject(String sSqlID, Class c)
	{
		return this.getJdbcTemplate().queryForObject(sSqlID, c);
	}

	public Object queryJdbcTemplateObject(String sDataSource, String sSqlID, Class c)
	{
		return this.getJdbcTemplate(sDataSource).queryForObject(sSqlID, c);
	}

	public Object queryJdbcTemplateObject(String sSqlID, Object[] args, Class c)
	{
		return this.getJdbcTemplate().queryForObject(sSqlID, args, c);
	}

	public Object queryJdbcTemplateObject(String sDataSource, String sSqlID, Object[] args, Class c)
	{
		return this.getJdbcTemplate(sDataSource).queryForObject(sSqlID, args, c);
	}

	public List queryJdbcTemplateList(String sSqlID)
	{
		return this.getJdbcTemplate().queryForList(sSqlID);
	}

	public List queryJdbcTemplateList(String sDataSource, String sSqlID)
	{
		return this.getJdbcTemplate(sDataSource).queryForList(sSqlID);
	}
	
	public int updateJdbcTemplate(String sSql)
	{
		return this.getJdbcTemplate().update(sSql);
	}

	public int updateJdbcTemplate(String sDataSource, String sSql)
	{
		return this.getJdbcTemplate(sDataSource).update(sSql);
	}
	
	public int updateJdbcTemplate(String sSql, Object[] args)
	{
		return this.getJdbcTemplate().update(sSql, args);
	}

	public int updateJdbcTemplate(String sDataSource, String sSql, Object[] args)
	{
		return this.getJdbcTemplate(sDataSource).update(sSql, args);
	}
}
